home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / rotate.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  11KB  |  478 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "func.h"
  13. #include "object.h"
  14. #include "paintop.h"
  15.  
  16. #define            TOLERANCE    7
  17.  
  18. extern            (*canvas_kbd_proc)();
  19. extern            (*canvas_locmove_proc)();
  20. extern            (*canvas_leftbut_proc)();
  21. extern            (*canvas_middlebut_proc)();
  22. extern            (*canvas_rightbut_proc)();
  23. extern            null_proc();
  24. extern            set_popupmenu();
  25.  
  26. extern F_line        *line_search(), *copy_line();
  27. extern F_ellipse    *ellipse_search(), *copy_ellipse();
  28. extern F_ellipse    *ellipse_point_search();
  29. extern F_spline        *spline_search(), *copy_spline();
  30. extern F_arc        *arc_point_search(), *copy_arc();
  31. extern F_compound    *compound_search(), *copy_compound();
  32.  
  33. extern F_compound    objects;
  34.  
  35. extern int        rotate_angle;
  36. extern int        pointmarker_shown;
  37. extern int        foreground_color, background_color;
  38.  
  39. static int        copy;
  40.             init_rotate();
  41.             init_copynrotate();
  42.  
  43. rotate_selected()
  44. {
  45.     canvas_kbd_proc = null_proc;
  46.     canvas_locmove_proc = null_proc;
  47.     canvas_leftbut_proc = init_copynrotate;
  48.     canvas_middlebut_proc = init_rotate;
  49.     canvas_rightbut_proc = set_popupmenu;
  50.     set_cursor(&pick15_cursor);
  51.     }
  52.  
  53. init_rotate(x, y)
  54. int    x, y;
  55. {
  56.     copy = 0;
  57.     rotate_search(x, y);
  58.     }
  59.  
  60. init_copynrotate(x, y)
  61. int    x, y;
  62. {
  63.     copy = 1;
  64.     rotate_search(x, y);
  65.     }
  66.  
  67. rotate_search(x, y)
  68. int    x, y;
  69. {
  70.     F_line        *l;
  71.     F_arc        *a;
  72.     F_ellipse    *e;
  73.     F_spline    *s;
  74.     F_compound    *c;
  75.     int        px, py;
  76.  
  77.     if ((l = line_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  78.         init_rotateline(l, px, py);
  79.         }
  80.     else if ((e = ellipse_point_search(x, y, TOLERANCE, &px)) != NULL) {
  81.         if (px == 0)
  82.         init_rotateellipse(e, e->start.x, e->start.y);
  83.         else
  84.         init_rotateellipse(e, e->end.x, e->end.y);
  85.         }
  86.     else if ((e = ellipse_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  87.         init_rotateellipse(e, x, y);
  88.         }
  89.     else if ((a = arc_point_search(x, y, TOLERANCE, &px)) != NULL) {
  90.         init_rotatearc(a, a->point[px].x, a->point[px].y);
  91.         }
  92.     else if ((s = spline_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  93.         init_rotatespline(s, px, py);
  94.         }
  95.     else if ((c = compound_search(x, y, TOLERANCE, &px, &py)) != NULL) {
  96.         init_rotatecompound(c, px, py);
  97.         }
  98.     else {
  99.         return;
  100.         }
  101.     set_modifiedflag();
  102.     }
  103.  
  104. init_rotateline(l, px, py)
  105. F_line    *l;
  106. int    px, py;
  107. {
  108.     F_line    *line;
  109.  
  110.     win_setmouseposition(canvas_swfd, px, py);
  111.     if (pointmarker_shown) toggle_linepointmarker(l);
  112.     if (copy) {
  113.         line = copy_line(l);
  114.         rotate_line(line, px, py, rotate_angle);
  115.         insert_line(&objects.lines, line);
  116.         clean_up();
  117.         set_action_object(F_CREATE, O_POLYLINE);
  118.         draw_line(line, PAINT);
  119.         }
  120.     else {
  121.         draw_line(l, ERASE);
  122.         rotate_line(l, px, py, rotate_angle);
  123.         clean_up();
  124.         set_action_object(F_ROTATE, O_POLYLINE);
  125.         set_lastangle(rotate_angle);
  126.         set_lastposition(px, py);
  127.         draw_line(l, PAINT);
  128.         line = l;
  129.         }
  130.     if (pointmarker_shown) {
  131.         if (copy) toggle_linepointmarker(line);
  132.         toggle_linepointmarker(l);
  133.         }
  134.     set_latestline(line);
  135.     }
  136.  
  137. init_rotateellipse(e, px, py)
  138. F_ellipse    *e;
  139. int        px, py;
  140. {
  141.     F_ellipse    *ellipse;
  142.  
  143.     win_setmouseposition(canvas_swfd, px, py);
  144.     if (pointmarker_shown) toggle_ellipsepointmarker(e);
  145.     if (copy) {
  146.         ellipse = copy_ellipse(e);
  147.         rotate_ellipse(ellipse, px, py, rotate_angle);
  148.         insert_ellipse(&objects.ellipses, ellipse);
  149.         clean_up();
  150.         set_action_object(F_CREATE, O_ELLIPSE);
  151.         draw_ellipse(ellipse, PAINT);
  152.         }
  153.     else {
  154.         draw_ellipse(e, background_color);
  155.         rotate_ellipse(e, px, py, rotate_angle);
  156.         clean_up();
  157.         set_action_object(F_ROTATE, O_ELLIPSE);
  158.         set_lastangle(rotate_angle);
  159.         set_lastposition(px, py);
  160.         draw_ellipse(e, foreground_color);
  161.         ellipse = e;
  162.         }
  163.     if (pointmarker_shown) {
  164.         if (copy) toggle_ellipsepointmarker(ellipse);
  165.         toggle_ellipsepointmarker(e);
  166.         }
  167.     set_latestellipse(ellipse);
  168.     }
  169.  
  170. init_rotatearc(a, px, py)
  171. F_arc    *a;
  172. int    px, py;
  173. {
  174.     F_arc    *arc;
  175.  
  176.     win_setmouseposition(canvas_swfd, px, py);
  177.     if (pointmarker_shown) toggle_arcpointmarker(a);
  178.     if (copy) {
  179.         arc = copy_arc(a);
  180.         rotate_arc(arc, px, py, rotate_angle);
  181.         insert_arc(&objects.arcs, arc);
  182.         clean_up();
  183.         set_action_object(F_CREATE, O_ARC);
  184.         draw_arc(arc, foreground_color);
  185.         }
  186.     else {
  187.         draw_arc(a, background_color);
  188.         rotate_arc(a, px, py, rotate_angle);
  189.         clean_up();
  190.         set_action_object(F_ROTATE, O_ARC);
  191.         set_lastangle(rotate_angle);
  192.         set_lastposition(px, py);
  193.         draw_arc(a, foreground_color);
  194.         arc = a;
  195.         }
  196.     if (pointmarker_shown) {
  197.         if (copy) toggle_arcpointmarker(arc);
  198.         toggle_arcpointmarker(a);
  199.         }
  200.     set_latestarc(arc);
  201.     }
  202.  
  203. init_rotatespline(s, px, py)
  204. F_spline    *s;
  205. int        px, py;
  206. {
  207.     F_spline    *spline;
  208.  
  209.     win_setmouseposition(canvas_swfd, px, py);
  210.     if (pointmarker_shown) toggle_splinepointmarker(s);
  211.     if (copy) {
  212.         spline = copy_spline(s);
  213.         rotate_spline(spline, px, py, rotate_angle);
  214.         insert_spline(&objects.splines, spline);
  215.         clean_up();
  216.         set_action_object(F_CREATE, O_SPLINE);
  217.         draw_spline(spline, PAINT);
  218.         }
  219.     else {
  220.         draw_spline(s, ERASE);
  221.         rotate_spline(s, px, py, rotate_angle);
  222.         clean_up();
  223.         set_action_object(F_ROTATE, O_SPLINE);
  224.         set_lastangle(rotate_angle);
  225.         set_lastposition(px, py);
  226.         draw_spline(s, PAINT);
  227.         spline = s;
  228.         }
  229.     if (pointmarker_shown) {
  230.         if (copy) toggle_splinepointmarker(spline);
  231.         toggle_splinepointmarker(s);
  232.         }
  233.     set_latestspline(spline);
  234.     }
  235.  
  236. init_rotatecompound(c, px, py)
  237. F_compound    *c;
  238. int        px, py;
  239. {
  240.     F_compound    *compound;
  241.  
  242.     win_setmouseposition(canvas_swfd, px, py);
  243.     set_temp_cursor(&wait_cursor);
  244.     if (copy) {
  245.         compound = copy_compound(c);
  246.         rotate_compound(compound, px, py, rotate_angle);
  247.         insert_compound(&objects.compounds, compound);
  248.         clean_up();
  249.         set_action_object(F_CREATE, O_COMPOUND);
  250.         draw_compound(compound);
  251.         draw_compoundbox(compound, INV_PAINT);
  252.         }
  253.     else {
  254.         draw_compoundbox(c, INV_PAINT);
  255.         erase_compound(c);
  256.         rotate_compound(c, px, py, rotate_angle);
  257.         clean_up();
  258.         set_action_object(F_ROTATE, O_COMPOUND);
  259.         set_lastangle(rotate_angle);
  260.         set_lastposition(px, py);
  261.         draw_compound(c);
  262.         draw_compoundbox(c, INV_PAINT);
  263.         compound = c;
  264.         }
  265.     set_latestcompound(compound);
  266.     set_temp_cursor(cur_cursor);
  267.     }
  268.  
  269. rotate_line(l, x, y, rotate_angle)
  270. F_line    *l;
  271. int    x, y, rotate_angle;
  272. {
  273.     F_point    *p;
  274.     int    dx;
  275.  
  276.     switch(rotate_angle) {
  277.         case 270 :
  278.         for (p = l->points; p != NULL; p = p->next) {
  279.             dx = p->x - x;
  280.             p->x = x + (y - p->y);
  281.             p->y = y + dx;
  282.             }
  283.         break;
  284.         case 90 :
  285.         for (p = l->points; p != NULL; p = p->next) {
  286.             dx = p->x - x;
  287.             p->x = x - (y - p->y);
  288.             p->y = y - dx;
  289.             }
  290.         break;
  291.         }
  292.     }
  293.  
  294. rotate_spline(s, x, y, rotate_angle)
  295. F_spline    *s;
  296. int        x, y, rotate_angle;
  297. {
  298.     F_point        *p;
  299.     F_control    *cp;
  300.     int        dx;
  301.  
  302.     switch(rotate_angle) {
  303.         case 270 :
  304.         for (p = s->points; p != NULL; p = p->next) {
  305.             dx = p->x - x;
  306.             p->x = x + (y - p->y);
  307.             p->y = y + dx;
  308.             }
  309.         for (cp = s->controls; cp != NULL; cp = cp->next) {
  310.             dx = cp->lx - x;
  311.             cp->lx = x + (y - cp->ly);
  312.             cp->ly = y + dx;
  313.             dx = cp->rx - x;
  314.             cp->rx = x + (y - cp->ry);
  315.             cp->ry = y + dx;
  316.             }
  317.         break;
  318.         case 90 :
  319.         for (p = s->points; p != NULL; p = p->next) {
  320.             dx = p->x - x;
  321.             p->x = x - (y - p->y);
  322.             p->y = y - dx;
  323.             }
  324.         for (cp = s->controls; cp != NULL; cp = cp->next) {
  325.             dx = cp->lx - x;
  326.             cp->lx = x - (y - cp->ly);
  327.             cp->ly = y - dx;
  328.             dx = cp->rx - x;
  329.             cp->rx = x - (y - cp->ry);
  330.             cp->ry = y - dx;
  331.             }
  332.         break;
  333.         }
  334.     }
  335.  
  336. rotate_text(t, x, y, rotate_angle)
  337. F_text    *t;
  338. int    x, y, rotate_angle;
  339. {
  340.     int    dx;
  341.  
  342.     switch(rotate_angle) {
  343.         case 270 :
  344.         dx = t->base_x - x;
  345.         t->base_x = x - (t->base_y - y);
  346.         t->base_y = y + dx;
  347.         break;
  348.         case 90 :    
  349.         dx = t->base_x - x;
  350.         t->base_x = x + (t->base_y - y);
  351.         t->base_y = y - dx;
  352.         break;
  353.         }
  354.     }
  355.  
  356. rotate_ellipse(e, x, y, rotate_angle)
  357. F_ellipse    *e;
  358. int        x, y, rotate_angle;
  359. {
  360.     int    dx;
  361.  
  362.     switch(rotate_angle) {
  363.         case 270 :
  364.         dx = e->center.x - x;
  365.         e->center.x = x - (e->center.y - y);
  366.         e->center.y = y + dx;
  367.         dx = e->radiuses.x;
  368.         e->radiuses.x = e->radiuses.y;
  369.         e->radiuses.y = dx;
  370.         dx = e->start.x - x;
  371.         e->start.x = x - (e->start.y - y);
  372.         e->start.y = y + dx;
  373.         dx = e->end.x - x;
  374.         e->end.x = x - (e->end.y - y);
  375.         e->end.y = y + dx;
  376.         break;
  377.         case 90 :    
  378.         dx = e->center.x - x;
  379.         e->center.x = x + (e->center.y - y);
  380.         e->center.y = y - dx;
  381.         dx = e->radiuses.x;
  382.         e->radiuses.x = e->radiuses.y;
  383.         e->radiuses.y = dx;
  384.         dx = e->start.x - x;
  385.         e->start.x = x + (e->start.y - y);
  386.         e->start.y = y - dx;
  387.         dx = e->end.x - x;
  388.         e->end.x = x + (e->end.y - y);
  389.         e->end.y = y - dx;
  390.         break;
  391.         }
  392.     }
  393.  
  394. rotate_arc(a, x, y, rotate_angle)
  395. F_arc    *a;
  396. int    x, y, rotate_angle;
  397. {
  398.     int    dx;
  399.  
  400.     switch(rotate_angle) {
  401.         case 270 :
  402.         dx = a->center.x - x;
  403.         a->center.x = x - (a->center.y - y);
  404.         a->center.y = y + dx;
  405.         dx = a->point[0].x - x;
  406.         a->point[0].x = x - (a->point[0].y - y);
  407.         a->point[0].y = y + dx;
  408.         dx = a->point[1].x - x;
  409.         a->point[1].x = x - (a->point[1].y - y);
  410.         a->point[1].y = y + dx;
  411.         dx = a->point[2].x - x;
  412.         a->point[2].x = x - (a->point[2].y - y);
  413.         a->point[2].y = y + dx;
  414.         break;
  415.         case 90 :    
  416.         dx = a->center.x - x;
  417.         a->center.x = x + (a->center.y - y);
  418.         a->center.y = y - dx;
  419.         dx = a->point[0].x - x;
  420.         a->point[0].x = x + (a->point[0].y - y);
  421.         a->point[0].y = y - dx;
  422.         dx = a->point[1].x - x;
  423.         a->point[1].x = x + (a->point[1].y - y);
  424.         a->point[1].y = y - dx;
  425.         dx = a->point[2].x - x;
  426.         a->point[2].x = x + (a->point[2].y - y);
  427.         a->point[2].y = y - dx;
  428.         break;
  429.         }
  430.     }
  431.  
  432. /*#define            min(a, b)    (((a) < (b)) ? (a) : (b))*/
  433. /*#define            max(a, b)    (((a) > (b)) ? (a) : (b))*/
  434.  
  435. rotate_compound(c, x, y, rotate_angle)
  436. F_compound    *c;
  437. int        x, y, rotate_angle;
  438. {
  439.     F_line        *l;
  440.     F_arc        *a;
  441.     F_ellipse    *e;
  442.     F_spline    *s;
  443.     F_text        *t;
  444.     F_compound    *c1;
  445.     int        x1, y1, x2, y2;
  446.  
  447.     switch(rotate_angle) {
  448.         case 270 :
  449.         x1 = x - (c->nwcorner.y - y);
  450.         y1 = y + (c->nwcorner.x - x);
  451.         x2 = x - (c->secorner.y - y);
  452.         y2 = y + (c->secorner.x - x);
  453.         break;
  454.         case 90 :    
  455.         x1 = x + (c->nwcorner.y - y);
  456.         y1 = y - (c->nwcorner.x - x);
  457.         x2 = x + (c->secorner.y - y);
  458.         y2 = y - (c->secorner.x - x);
  459.         break;
  460.         }
  461.     c->nwcorner.x = min(x1, x2);
  462.     c->nwcorner.y = min(y1, y2);
  463.     c->secorner.x = max(x1, x2);
  464.     c->secorner.y = max(y1, y2);
  465.     for (l = c->lines; l != NULL; l = l->next)
  466.         rotate_line(l, x, y, rotate_angle);
  467.     for (a = c->arcs; a != NULL; a = a->next)
  468.         rotate_arc(a, x, y, rotate_angle);
  469.     for (e = c->ellipses; e != NULL; e = e->next)
  470.         rotate_ellipse(e, x, y, rotate_angle);
  471.     for (s = c->splines; s != NULL; s = s->next)
  472.         rotate_spline(s, x, y, rotate_angle);
  473.     for (t = c->texts; t != NULL; t = t->next)
  474.         rotate_text(t, x, y, rotate_angle);
  475.     for (c1 = c->compounds; c1 != NULL; c1 = c1->next)
  476.         rotate_compound(c1, x, y, rotate_angle);
  477.     }
  478.